﻿package com.bn.NNYY;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

public class Score {
	GameView gameView;
	final int space=5;//文字和力度条的距离
	private Bitmap defenBitmap;//得分位图
	Bitmap breakMarkBitmap;//冒号分隔符
	private Bitmap[] numberBitmaps;	//数字位图
	private int score=0;
	int endX=7*Constant.SCREEN_WIDTH/8;//数字的右上点坐标
	int endY=(int) Constant.BAR_Y;
	int numberWidth;//数字图片的宽	
	int numberHeight;//数字图片的高
	int textWidth;//得分图片的宽
	int textHeight;	//得分图片的高
	int breakMarkWidth;//冒号分割符的宽度
	int breakMarkHeight;//冒号分隔符的高度
	public Score(GameView gameView,Bitmap defenBitmap,Bitmap[] numberBitmaps,Bitmap breakMarkBitmap)
	{
		this.gameView=gameView;
		this.defenBitmap=defenBitmap;
		this.numberBitmaps=numberBitmaps;
		this.breakMarkBitmap=breakMarkBitmap;
		
		numberHeight=numberBitmaps[0].getWidth();//数字图片的高
		numberWidth=numberBitmaps[0].getHeight();//数字图片的宽		
		textWidth=defenBitmap.getWidth();//得分图片的宽
		textHeight=defenBitmap.getHeight();	//得分图片的高
		breakMarkWidth=breakMarkBitmap.getWidth();//冒号分割符的宽度
		breakMarkHeight=breakMarkBitmap.getHeight();//冒号分隔符的高度
	}
	//绘制得分的方法
	public void drawSelf(Canvas canvas,Paint paint,float offsetX,float offsetY)
	{		
		//绘制数字
		drawNumberBitmap(this.score,numberBitmaps,endX,endY,canvas, paint);
		//绘制“冒号分割符”
		String numberStr=this.score+"";
		int textX=endX-numberWidth*numberStr.length()-breakMarkWidth-space;
		int textY=endY;
		canvas.drawBitmap(breakMarkBitmap, textX+offsetX, textY+offsetY,paint);//绘制“得分”
		
		//绘制得分图片
		textX=endX-numberWidth*numberStr.length()-textWidth-breakMarkWidth-space-space;
		textY=endY;
		canvas.drawBitmap(defenBitmap, textX+offsetX, textY+offsetY,paint);//绘制“得分”
	}
	//增加得分的方法
	public void addScore(int score)
	{
		this.score+=score;
	}
	public int getScore()
	{
		return score;
	}
	//画数字图片的方法
	public void drawNumberBitmap(int number,Bitmap[] numberBitmaps,float endX,float endY,Canvas canvas,Paint paint)
	{
		String numberStr=number+"";
		for(int i=0;i<numberStr.length();i++)
		{
			char c=numberStr.charAt(i);
			canvas.drawBitmap//绘制"数字"
			(
					numberBitmaps[c-'0'], 
					endX-numberWidth*(numberStr.length()-i), 
					endY, 
					paint
			);
		}
	}
}
